home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amoszine 3
/
Amoszine 3.adf
/
MORE_SOURCE
/
File_Select.AMOS.pp
/
File_Select.AMOS
/
File_Select.amosSourceCode
Wrap
AMOS Source Code
|
1992-02-26
|
17KB
|
663 lines
'
' File Selector Routine
' ~~~~~~~~~~~~~~~~~~~~~
' June '93
' ~~~~~~~~
' Author: Steve Pullinger
' Feel free to use this routine to disguise that you wrote your program
' in Amos
' This routine uses a double buffered screen
' and the autoback system is switched off
'
' The Autoback 0 command would probably be executed in the main program
' that calls this routine.
' If so then you may need to delete the command from this routine.
'
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Version 2
' Uses search filter
'
' Initialise File Selector
'
' Maximum Number of files to deal with
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MX_NO_FILES=60
'
' Storage lists for selector
' ~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim FILE_LIST$(MX_NO_FILES)
Dim DEV_LIST$(30)
'
' Set up Fonts so I can use Graphic Text
' This lets me position text using pixel co-ordinates
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get Rom Fonts
Set Font 2
'
' Call Selector routine - passing it a title and search path
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE_SELECTOR["Steve's File Selector","df0:",""]
'
' Print Selected path (returned from procedure)
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' String is either a full path, CANCELLED or NULL_FILE
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Print Param$
'
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' The routine
' ~~~~~~~~~~~
Procedure FILE_SELECTOR[TITLE$,PATH$,FILTER$]
Shared FILE_LIST$(),DEV_LIST$()
Reserve Zone
'
CUR$=" "
' Set Up Screen
' ~~~~~~~~~~~~~
Screen Open 7,320,200,4,LORES
Screen Display 7,128,50,,
Curs Off : Flash Off
Palette $0,$FFF,$668,$2F4
Cls 2
' Write Title in Box
' ~~~~~~~~~~~~~~~~~~
Ink 0,2
L=Text Length(TITLE$)
Text 160-L/2,12,TITLE$
Ink 1
Draw 160-L/2-3,2 To 160+L/2+1,2
Draw 160-L/2-3,2 To 160-L/2-3,15
Ink 0
Draw 160+L/2+1,2 To 160+L/2+1,15
Draw 160-L/2-3,15 To 160+L/2+1,15
'
Reserve Zone 18
' File List Window
' ~~~~~~~~~~~~~~~~
Ink 0
Bar 10,20 To 300,120
TLX=10 : BRX=300
TLY=20 : BRY=30
For Z=1 To 10
Set Zone Z,TLX,TLY To BRX,BRY
Add TLY,10
Add BRY,10
Next Z
'
' Box for Slider
' ~~~~~~~~~~~~~~
Ink 0
Draw 305,30 To 315,30
Draw 305,30 To 305,110
Ink 1
Draw 315,30 To 315,110
Draw 305,110 To 315,110
Set Zone 18,305,30 To 315,110
'
' Slider Up
' ~~~~~~~~~
Ink 1
Draw 305,20 To 315,20
Draw 305,20 To 305,29
Ink 0
Draw 315,20 To 315,29
Draw 305,29 To 315,29
Draw 310,22 To 307,27
Draw 310,22 To 313,27
Set Zone 16,305,20 To 315,29
'
' Slider Down
' ~~~~~~~~~~~
Ink 1
Draw 305,111 To 315,111
Draw 305,111 To 305,120
Ink 0
Draw 305,120 To 315,120
Draw 315,111 To 315,120
Draw 310,119 To 307,114
Draw 310,119 To 313,114
Set Zone 17,305,111 To 315,120
'
' String Gadgets
' ~~~~~~~~~~~~~~
Ink 0
T$="Path:"
Text 10,139,T$
Bar 50,130 To 260,140
Set Zone 11,50,130 To 260,140
Ink 3,0
Text 52,139,PATH$
Ink 0,2
T$="File:"
Text 10,159,T$
Bar 50,150 To 260,160
Set Zone 12,50,150 To 260,160
'
' Control Buttons
' ~~~~~~~~~~~~~~~
Ink 0
T$="OK"
L=Text Length(T$)
Text 80-L/2,189,T$
Ink 1
Draw 60,180 To 98,180
Draw 60,180 To 60,191
Ink 0
Draw 98,180 To 98,191
Draw 60,191 To 98,191
Set Zone 13,60,180 To 98,191
'
T$="Disks"
L=Text Length(T$)
Text 160-L/2,189,T$
Ink 1
Draw 132,180 To 186,180
Draw 132,180 To 132,191
Ink 0
Draw 186,180 To 186,191
Draw 132,191 To 186,191
Set Zone 14,132,180 To 186,191
'
T$="Cancel"
L=Text Length(T$)
Text 240-L/2,189,T$
Ink 1
Draw 208,180 To 270,180
Draw 208,180 To 208,191
Ink 0
Draw 270,180 To 270,191
Draw 208,191 To 270,191
Set Zone 15,208,180 To 270,191
'
'
Double Buffer
Autoback 0
'
' Screen Setup Complete
' ~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
' Error Check on Path$
' ~~~~~~~~~~~~~~~~~~~~
If PATH$=""
PATH$="NULL"
End If
If Exist(PATH$)=0
PATH$="DF0:"
End If
If Exist(PATH$)
TEMP$=Mid$(PATH$,Len(PATH$),1)
If PATH$<>""
If Exist(PATH$)
If(TEMP$<>":") and(TEMP$<>"/")
PATH$=PATH$+"/"
End If
Ink 0
Bar 50,130 To 260,140
Ink 3,0
Text 52,139,PATH$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
Gosub DISK_READ
Gosub FILE_PRINT
End If
End If
End If
'
' Main Loop
' ~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do
If Mouse Key=1
ZN=Mouse Zone
'
' Check Up Slider
' ~~~~~~~~~~~~~~~
If ZN=16
If DEVICE=0
If FILE_LIST_POINTER>0
Dec FILE_LIST_POINTER
Gosub FILE_PRINT
End If
End If
If DEVICE=1
If DEV_LIST_POINTER>0
Dec DEV_LIST_POINTER
Gosub DEV_PRINT
End If
End If
End If
'
' Check Down Slider
' ~~~~~~~~~~~~~~~~~
If ZN=17
If DEVICE=0
If FILE_LIST_POINTER+10<NO_FILES
Inc FILE_LIST_POINTER
Gosub FILE_PRINT
End If
End If
If DEVICE=1
If DEV_LIST_POINTER+10<NO_DEVS
Inc DEV_LIST_POINTER
End If
Gosub DEV_PRINT
End If
End If
'
' Check Slider Bar
' ~~~~~~~~~~~~~~~~
If ZN=18
OLD_POS=POS
POS=Y Screen(Y Mouse)-30
If DEVICE=0
POS=POS/(78/NO_FILES)
If POS>NO_FILES-10
POS=NO_FILES-10
End If
If POS<0
POS=0
End If
If OLD_POS<>POS
FILE_LIST_POINTER=POS
Gosub FILE_PRINT
End If
End If
If DEVICE=1
POS=POS/(78/NO_DEVS)
If POS>NO_DEVS-10
POS=NO_DEVS-10
End If
If POS<0
POS=0
End If
If OLD_POS<>POS
DEV_LIST_POINTER=POS
Gosub DEV_PRINT
End If
End If
OLD_POS=POS
End If
'
' Check Path String Gadget
' ~~~~~~~~~~~~~~~~~~~~~~~~
If ZN=11
CANCEL=0
Clear Key
Repeat
' Check for different Zone
' ~~~~~~~~~~~~~~~~~~~~~~~~
If Mouse Key=1
ZN=Mouse Zone
End If
If ZN<>11
CANCEL=1
End If
' Read Keyboard
' ~~~~~~~~~~~~~
K$=Inkey$
' Check for Return Key
' ~~~~~~~~~~~~~~~~~~~~
If Asc(K$)=13
CANCEL=1
K$=""
TEMP$=Mid$(PATH$,Len(PATH$),1)
If PATH$<>""
If Exist(PATH$)
If(TEMP$<>":") and(TEMP$<>"/")
PATH$=PATH$+"/"
End If
Gosub DISK_READ
Gosub FILE_PRINT
End If
End If
End If
' Check for backspace
' ~~~~~~~~~~~~~~~~~~~
If Asc(K$)=8
PATH$=Left$(PATH$,Len(PATH$)-1)
Ink 0
Bar 50,130 To 260,140
Ink 3
Text 52,139,PATH$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
End If
' Check for Alphanumeric Keys
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~
If(Asc(K$)<127) and(Asc(K$)>32)
PATH$=PATH$+K$
Text 52,139,PATH$
End If
GADGET_CURSOR=52+Text Length(PATH$)
Y_GADGET=139
Gosub GADGET
Until CANCEL>0
If CANCEL=1
Ink 0
Bar 50,130 To 260,140
Ink 3
Text 52,139,PATH$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
End If
End If
'
' End of Path Gadget
' ~~~~~~~~~~~~~~~~~~
'
' Check File String Gadget
' ~~~~~~~~~~~~~~~~~~~~~~~~
If ZN=12
CANCELF=0
Clear Key
Repeat
' Check for different Zone
' ~~~~~~~~~~~~~~~~~~~~~~~~
If Mouse Key=1
ZN=Mouse Zone
End If
If ZN<>12
CANCELF=1
End If
' Read Keyboard
' ~~~~~~~~~~~~~
K$=Inkey$
' Check for Return Key
' ~~~~~~~~~~~~~~~~~~~~
If Asc(K$)=13
CANCELF=1
K$=""
If FILENAME$<>""
If Exist(PATH$)
If Exist(FILENAME$)
NEW_PATH$=PATH$+FILENAME$
CANCELF=2
End If
End If
End If
End If
' Check for backspace
' ~~~~~~~~~~~~~~~~~~~
If Asc(K$)=8
FILENAME$=Left$(FILENAME$,Len(FILENAME$)-1)
Ink 0
Bar 50,150 To 260,160
Ink 3
Text 52,159,FILENAME$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
End If
' Check for Alphanumeric Keys
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~
If(Asc(K$)<127) and(Asc(K$)>32)
FILENAME$=FILENAME$+K$
Text 52,159,FILENAME$
End If
GADGET_CURSOR=52+Text Length(FILENAME$)
Y_GADGET=159
Gosub GADGET
Until CANCELF>0
If CANCELF>0
Ink 0
Bar 50,150 To 260,160
Ink 3
Text 52,159,FILENAME$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
End If
If CANCELF=2
Goto LEAVE
End If
End If
'
' End of File Name Gadget
' ~~~~~~~~~~~~~~~~~~~~~~~
' Check for OK Button
' ~~~~~~~~~~~~~~~~~~~~~
If ZN=13
If FILENAME$=""
FILENAME$="NULL_FILE"
End If
If Exist(PATH$)
NEW_PATH$=PATH$+FILENAME$
Goto LEAVE
End If
End If
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
' Check for Cancel Button
' ~~~~~~~~~~~~~~~~~~~~~~~
If ZN=15
NEW_PATH$="CANCELLED"
Goto LEAVE
End If
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Check for Disk Button
' ~~~~~~~~~~~~~~~~~~~~~
If ZN=14
Gosub DEV_READ
Gosub DEV_PRINT
DEVICE=1
End If
'
' Check List Window
' ~~~~~~~~~~~~~~~~~
If(ZN>0) and(ZN<11)
If DEVICE=1
Gosub DEV_SELECT
Else
Gosub FILE_SELECT
End If
End If
End If
Loop
'
' End of main loop
' ~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
End
'
' SubRoutines
' ~~~~~~~~~~~
'
' Get Selection from Devices List into Path$
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DEV_SELECT:
If ZN+DEV_LIST_POINTER<=NO_DEVS
PATH$=DEV_LIST$(ZN+DEV_LIST_POINTER-1)
Ink 0
Bar 50,130 To 260,140
Ink 3
Text 52,139,PATH$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
Gosub DISK_READ
Gosub FILE_PRINT
DEVICE=0
End If
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Get Selection from File List
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE_SELECT:
If ZN>0
If ZN+FILE_LIST_POINTER<=NO_FILES
FILENAME$=FILE_LIST$(ZN+FILE_LIST_POINTER-1)
'
' Is it a File?
' ~~~~~~~~~~~~~
If Left$(FILENAME$,1)=" "
FILENAME$=Mid$(FILENAME$,2,Len(FILENAME$))
Ink 0
Bar 50,150 To 260,160
Ink 3
Text 52,159,FILENAME$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
End If
'
' Or is it a Directory?
' ~~~~~~~~~~~~~~~~~~~~~
If Left$(FILENAME$,1)="*"
FILENAME$=Mid$(FILENAME$,2,Len(FILENAME$))
PATH$=PATH$+FILENAME$
FILENAME$=""
TEMP$=Mid$(PATH$,Len(PATH$),1)
If PATH$<>""
If Exist(PATH$)
If(TEMP$<>":") and(TEMP$<>"/")
PATH$=PATH$+"/"
Ink 0
Bar 50,130 To 260,140
Ink 3
Text 52,139,PATH$
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
End If
Gosub DISK_READ
Gosub FILE_PRINT
End If
End If
End If
End If
End If
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
DEV_READ:
' Read Devices into Dev_List()
'
NO_DEVS=0 : DEV_LIST_POINTER=0
D$=Dev First$("")
While D$<>""
D$=D$-" "
' Store D$ in Data Array
'
DEV_LIST$(NO_DEVS)=D$
Inc NO_DEVS
D$=Dev Next$
Wend
Return
'
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DEV_PRINT:
' Print Dev List to List Window
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ink 0
Bar 10,20 To 300,120
Y_FILE=29
Ink 3,0
For PRNT_DEV=DEV_LIST_POINTER To DEV_LIST_POINTER+9
If PRNT_DEV<NO_DEVS
Text 12,Y_FILE,DEV_LIST$(PRNT_DEV)
Add Y_FILE,10
End If
Next PRNT_DEV
' Draw Slider
Set Slider 2,2,2,1,1,1,1,1
Vslider 306,31 To 314,109,NO_DEVS,DEV_LIST_POINTER,(78/NO_DEVS)+8
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
Repeat
Until Mouse Key=0
ZN=0
Return
'
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GADGET:
'
' Inverse cursor in string gadgets
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Gr Writing 4+1
Text GADGET_CURSOR,Y_GADGET,CUR$
Gr Writing 1
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
Return
'
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE_PRINT:
' Print File List to List Window
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ink 0
Bar 10,20 To 300,120
Y_FILE=29
Ink 3,0
For PRNT_FILE=FILE_LIST_POINTER To FILE_LIST_POINTER+9
If PRNT_FILE<NO_FILES
Text 12,Y_FILE,FILE_LIST$(PRNT_FILE)
Add Y_FILE,10
End If
Next PRNT_FILE
' Draw Slider
Set Slider 2,2,2,1,1,1,1,1
If NO_FILES>0
Vslider 306,31 To 314,109,NO_FILES,FILE_LIST_POINTER,(78/NO_FILES)+8
End If
Screen Swap
Wait Vbl
Screen Copy Physic To Logic
Repeat
Until Mouse Key=0
ZN=0
Return
'
' End of FILE_PRINT Routine
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
DISK_READ:
'
' Read Directory into File_List()
'
If Exist(PATH$)
NO_FILES=0 : FILE_LIST_POINTER=0
F$=Dir First$(PATH$+FILTER$)
While F$<>""
Gosub STRIPOUT
' Store F$ in Data Array
'
FILE_LIST$(NO_FILES)=F$
Inc NO_FILES
F$=Dir Next$
Gosub STRIPOUT
Wend
End If
Return
' End of DISK_READ Routine
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
STRIPOUT:
'
' Strip out unwanted characters
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
L=Len(F$)
CHARPOS=1
While CHARPOS<L
If Mid$(F$,CHARPOS,1)=" "
If CHARPOS>1
F$=Left$(F$,CHARPOS-1)
CHARPOS=L
Exit
End If
End If
Inc CHARPOS
Wend
Return
'
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LEAVE:
Screen Close 7
End Proc[NEW_PATH$]